import { data } from '../../http/roots';

export const loadJs = function ( callback ) {
  //拿取创建头部，尾部的js
  let rrm_header = document.querySelector('#rrm_header');
  let rrm_footer = document.querySelector('#rrm_footer');
  if( rrm_header ){
    let parent =  document.querySelector('body');
    parent.removeChild(rrm_header);
    parent.removeChild(rrm_footer);
    rrm_header = rrm_footer = parent = null;
  }
  let fm = document.createElement('script');
  fm.type = 'text/javascript';
  fm.src = data.roots[ data.index ] + '/site/header.js?a=' + Math.floor(Math.random()*(1-10000) + 10000);
  let s = document.getElementsByTagName('meta')[0];
  s.parentNode.insertBefore(fm, s);
  //头部滚动背景渐变
  // function changeHdBg() {
  //   let off = 1;
  //   if (off < 1) {
  //     return;
  //   }
  //   let $header = document.querySelector('#rrm_header');
  //   let t = 700, m = Math.min(document.documentElement.scrollTop || document.body.scrollTop, t) / t;
  //   console.log('$header',$header)
  //   let opacity = Number(m) + 0.23;
  //   let cssTxt = 'background:rgba(23, 23, 23, ' + opacity + ')';
  //   $header.style.cssText = cssTxt;
  //   $header = null;
  // }
  fm.onload = fm.onreadystatechange = function(){
    // changeHdBg();
    // window.addEventListener('scroll', changeHdBg, true);
    s = fm = null;
    rrm_header = rrm_footer = null;
  };
};
